package com.ruoyi.performance.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.performance.mapper.TCollectScoreMapper;
import com.ruoyi.performance.domain.TCollectScore;
import com.ruoyi.performance.service.ITCollectScoreService;

/**
 * 分数汇总Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@Service
public class TCollectScoreServiceImpl implements ITCollectScoreService 
{
    @Autowired
    private TCollectScoreMapper tCollectScoreMapper;

    /**
     * 查询分数汇总
     * 
     * @param id 分数汇总主键
     * @return 分数汇总
     */
    @Override
    public TCollectScore selectTCollectScoreById(Long id)
    {
        return tCollectScoreMapper.selectTCollectScoreById(id);
    }

    /**
     * 查询分数汇总列表
     * 
     * @param tCollectScore 分数汇总
     * @return 分数汇总
     */
    @Override
    public List<TCollectScore> selectTCollectScoreList(TCollectScore tCollectScore)
    {
        String username = SecurityUtils.getUsername();
        if (username.equals("admin")){
            username = null;
        }
        tCollectScore.setTeacherName(username);
        return tCollectScoreMapper.selectTCollectScoreList(tCollectScore);
    }

    /**
     * 新增分数汇总
     * 
     * @param tCollectScore 分数汇总
     * @return 结果
     */
    @Override
    public int insertTCollectScore(TCollectScore tCollectScore)
    {
        tCollectScore.setCreateTime(DateUtils.getNowDate());
        return tCollectScoreMapper.insertTCollectScore(tCollectScore);
    }

    /**
     * 修改分数汇总
     * 
     * @param tCollectScore 分数汇总
     * @return 结果
     */
    @Override
    public int updateTCollectScore(TCollectScore tCollectScore)
    {
        tCollectScore.setLastScore(tCollectScore.getScore() + tCollectScore.getAddScore() + tCollectScore.getSubtractScore());
        return tCollectScoreMapper.updateTCollectScore(tCollectScore);
    }

    /**
     * 批量删除分数汇总
     * 
     * @param ids 需要删除的分数汇总主键
     * @return 结果
     */
    @Override
    public int deleteTCollectScoreByIds(Long[] ids)
    {
        return tCollectScoreMapper.deleteTCollectScoreByIds(ids);
    }

    /**
     * 删除分数汇总信息
     * 
     * @param id 分数汇总主键
     * @return 结果
     */
    @Override
    public int deleteTCollectScoreById(Long id)
    {
        return tCollectScoreMapper.deleteTCollectScoreById(id);
    }
}
